import { Component, OnInit, Input } from '@angular/core'
import { I18NService } from '@core'
import { Router, ActivatedRoute } from '@angular/router'
import { TitleService } from '@delon/theme'

import { IBaseInfoColumn } from '@shared/interfaces/baseInfo'
import { DetailBaseClass } from '@shared/classes/DetailBaseClass'
import { PageService } from '@shared/services/page.service'
import { IHoldReleaseDetail, EReleaseReason } from '@shared/interfaces/operation'
import { ECustomAcl } from '@shared/enums'
import { ACLService } from '@delon/acl'

@Component({
  selector: 'app-release-detail',
  templateUrl: './release-detail.component.html',
})
export class ReleaseDetailComponent extends DetailBaseClass<IHoldReleaseDetail> implements OnInit {
  @Input() releaseDetail: IHoldReleaseDetail
  firstColumns: IBaseInfoColumn[]
  secondColumns: IBaseInfoColumn[]

  constructor(
    public i18n: I18NService,
    public router: Router,
    public route: ActivatedRoute,
    public pageService: PageService,
  ) {
    super(pageService)
  }

  ngOnInit() {
    this.detailData = this.releaseDetail
    this.initFirstColumns()
    this.initSecondColumns()
    this.initColumns()
  }

  initFirstColumns(): void {
    this.firstColumns = [
      {
        span: 8,
        index: 'riskTime',
        label: '操作时间',
        labelI18n: 'OPERATION.HOLDRELEASE.DETAIL.RISKTIME',
        type: 'date',
        acl: [ECustomAcl.ReleaseDetailDate],
      },
      {
        span: 8,
        index: 'reason',
        label: '释放原因',
        labelI18n: 'OPERATION.HOLDRELEASE.DETAIL.RELEASE_REASON',
        pipe: this.getReason.bind(this),
      },
      {
        span: 8,
        index: 'operator',
        label: '操作用户',
        labelI18n: 'OPERATION.HOLDRELEASE.DETAIL.OPERATOR',
      },
    ]
  }

  initSecondColumns(): void {
    this.secondColumns = [
      {
        span: 24,
        index: 'remark',
        label: '备注',
        labelI18n: 'GENERAL.INFO.REMARK',
      },
    ]
  }

  getReason(reason: EReleaseReason): string {
    return this.i18n.fanyi(EReleaseReason[reason])
  }
}
